package com.imooc.vo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;


@Getter
public class ResultVo<T>{

    private Integer code;

    private String msg;

    private T data;

    private ResultVo() {
        this.code = 0;
        this.msg = "成功";
    }

    private ResultVo(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private ResultVo(Integer code, T data) {
        this.code = code;
        this.data = data;
    }

    private ResultVo(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    @JsonIgnore
    public boolean isSuccess() {
        return this.code == 0;
    }

    public static <T> ResultVo success() {
        return new ResultVo();
    }

    public static <T> ResultVo success(T data) {
        return new ResultVo(0, data);
    }

    public static <T> ResultVo successMessage(String msg, T data) {
        return new ResultVo(0, msg, data);
    }

    public static <T> ResultVo error(Integer code, String msg) {
        return new ResultVo(code, msg);
    }


}
